﻿#include "setting_plot_rect_dialog.h"
#include "ui_setting_plot_rect_dialog.h"

SettingPlotRectDialog::SettingPlotRectDialog(QWidget* parent) :
	QDialog(parent),
	ui(new Ui::SettingPlotRectDialog)
{
	ui->setupUi(this);
	setWindowTitle(QStringLiteral("区域设置"));

	connect(ui->pushButton_cancel_, &QPushButton::clicked, this, &SettingPlotRectDialog::Cancel);
	connect(ui->pushButton_ok_, &QPushButton::clicked, this, &SettingPlotRectDialog::OK);
}

SettingPlotRectDialog::~SettingPlotRectDialog()
{
	delete ui;
}

void SettingPlotRectDialog::SetCurrentRect(const QCPRange& xRange, const QCPRange& yRange)
{
	ui->doubleSpinBox_x1_->setValue(xRange.lower);
	ui->doubleSpinBox_x2_->setValue(xRange.upper);
	ui->doubleSpinBox_y1_->setValue(yRange.lower);
	ui->doubleSpinBox_y2_->setValue(yRange.upper);
}

void SettingPlotRectDialog::Cancel()
{
	close();
}

void SettingPlotRectDialog::OK()
{
	double x1 = ui->doubleSpinBox_x1_->value();
	double x2 = ui->doubleSpinBox_x2_->value();
	double y1 = ui->doubleSpinBox_y1_->value();
	double y2 = ui->doubleSpinBox_y2_->value();
	QCPRange xRange = x1 < x2 ? QCPRange(x1, x2) : QCPRange(x2, x1);
	QCPRange yRange = y1 < y2 ? QCPRange(y1, y2) : QCPRange(y2, y1);
	close();
	emit OkClickedSignal(xRange, yRange);
}
